﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.Depo
{
    public partial class GetPurchases : XForm
    {
        public GetPurchases()
        {
            InitializeComponent();
        }

        private void GetPurchases_Load(object sender, EventArgs e)
        {

            txtRollIds.EditValueChanged += new EventHandler(txtRollIds_EditValueChanged);
            gv.RowCellStyle += new RowCellStyleEventHandler(gv_RowCellStyle);
            gv.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gv_FocusedRowChanged);
        }

        void gv_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gv2.BestFitColumns();
        }

        void txtRollIds_EditValueChanged(object sender, EventArgs e)
        {
            string products = txtRollIds.EditValue.ToStr().Trim().Replace("\r\n", ",");
            if (products != string.Empty)
            {
                gv.Init("GetPurchases", products);
                gv.AddDetailGrid(gv2, "ProductId");

                gv2.FormatAsNumber(1, "Qty");
                gv2.FormatAsDate("GelisTarihi");

                gv.AddSummary();
                gv2.AddSummary();

                gv.BestFitColumns();
                gv2.BestFitColumns();
            }
        }

        void gv_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            GridView view = sender as GridView;
            if (e.RowHandle == gv.FocusedRowHandle)
                e.Appearance.BackColor = System.Drawing.Color.YellowGreen;
            else
                e.Appearance.Combine((e.RowHandle & 1) != 0 ? view.Appearance.EvenRow : view.Appearance.OddRow);

            switch (e.Column.FieldName)
            {
                case "PRO": //OPS..
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
            }

        }

    }
}